/****************************************************************************/
/* File: scs-image.h                                                        */
/* Desc: Specification file for the video image type                        */
/* Created: 2014-11-20                                                      */
/* Revised: 2014-11-21                                                      */
/* Authors: Sterling P. de Mille                                            */
/****************************************************************************/

// include once
#ifndef _SCS_IMAGE_H_
#define _SCS_IMAGE_H_

// core data types
#include "../Core/scs-types.h"
// core error codes
#include "../Core/scs-error.h"
// video color type
#include "scs-color.h"
// video display type
#include "scs-display.h"

// SDL framework
#include <SDL/SDL.h>
// SDL image support
#include <SDL/SDL_image.h>

// video image type
class SCSimage {
protected:

	SDL_Surface* m_pkImage;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    const static SCSint32u RED_MASK32 = 0xff000000;
    const static SCSint32u GREEN_MASK32 = 0x00ff0000;
    const static SCSint32u BLUE_MASK32 = 0x0000ff00;
    const static SCSint32u ALPHA_MASK32 = 0x000000ff;

    const static SCSint32u RED_MASK16 = 0xf800;
    const static SCSint32u GREEN_MASK16 = 0x07c0;
    const static SCSint32u BLUE_MASK16 = 0x003e;
    const static SCSint32u ALPHA_MASK16 = 0x0001;

#else
    const static SCSint32u RED_MASK32 = 0x000000ff;
    const static SCSint32u GREEN_MASK32 = 0x0000ff00;
    const static SCSint32u BLUE_MASK32 = 0x00ff0000;
    const static SCSint32u ALPHA_MASK32 = 0xff000000;

    const static SCSint32u RED_MASK16 = 0x001f;
    const static SCSint32u GREEN_MASK16 = 0x03e0;
    const static SCSint32u BLUE_MASK16 = 0x7c00;
    const static SCSint32u ALPHA_MASK16 = 0x8000;

#endif

public:

	SCSimage (const SCSint iSizeX, const SCSint iSizeY);
	SCSimage (const SCSimage& rkImage);
	~SCSimage ();

	void Init (const SCSint iSizeX, const SCSint iSizeY);

	SCSint SizeX () const;
	SCSint SizeY () const;

	SCSfloat GetRed (const SCSint iPosX, const SCSint iPosY) const;
	SCSfloat GetGreen (const SCSint iPosX, const SCSint iPosY) const;
	SCSfloat GetBlue (const SCSint iPosX, const SCSint iPosY) const;
	SCSfloat GetAlpha (const SCSint iPosX, const SCSint iPosY) const;

	SCSint32u GetPixel (const SCSint iPosX, const SCSint iPosY) const;

	void SetRed (const SCSfloat fRed, const SCSint iPosX, const SCSint iPosY);
	void SetGreen (const SCSfloat fGreen, const SCSint iPosX, const SCSint iPosY);
	void SetBlue (const SCSfloat fBlue, const SCSint iPosX, const SCSint iPosY);
	void SetAlpha (const SCSfloat fAlpha, const SCSint iPosX, const SCSint iPosY);

	void SetPixel (const SCSint32u iPixel, const SCSint iPosX, const SCSint iPosY);

	SCSint8u* Pixels ();

	SCSerror CopyImageArea (SCSimage& rkImage, SCSrectangle& rkSource, SCSrectangle& rkDestination);

	SCSerror SaveAsFile (const SCSstring& rsFilename);
	SCSerror LoadFromFile (const SCSstring& rsFilename);
};

#endif // _SCS_IMAGE_H_
